package com.xiaoying.chuguoliuxue;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.loader.ImageLoaderInterface;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.OnItemClick;

public class MainActivity extends BaseActivity {

    @BindView(R.id.vw_company_images)
    Banner vwCompanyImages;
    @BindView(R.id.lv1)
    com.xiaoying.chuguoliuxue.SV_ListView lv1;
    @BindView(R.id.lv2)
    com.xiaoying.chuguoliuxue.SV_ListView lv2;
    @BindView(R.id.lv3)
    com.xiaoying.chuguoliuxue.SV_ListView lv3;

    List<Integer> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        bannerInit();
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_main;
    }


    private void init() {
        data = new ArrayList<>();
        data.add(R.mipmap.ic_banner);
        data.add(R.mipmap.ic_banner);
        data.add(R.mipmap.ic_banner);
        data.add(R.mipmap.ic_banner);
        setTitle("黑子出国app");
        setRightTitleImage(R.mipmap.ic_loc);
        setRightTitleText("杭州");
        setLeftTitleImage(R.mipmap.ic_arrow_white);
        lv1.setAdapter(new MyAdapter2(this));
        lv2.setAdapter(new MyAdapter1(this));
        lv3.setAdapter(new MyAdapter3(this));
        addRightButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                time2000();
            }
        });
    }

    private void bannerInit() {
        vwCompanyImages.isAutoPlay(true);
        vwCompanyImages.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        vwCompanyImages.setImages(data);
        vwCompanyImages.setImageLoader(new ImageLoaderInterface() {
            @Override
            public void displayImage(Context context, Object path, View imageView) {
                ((ImageView) imageView).setImageResource((int) path);
            }

            @Override
            public View createImageView(Context context) {
                return new ImageView(context);
            }
        });
        vwCompanyImages.start();
    }

    @OnItemClick({R.id.lv1,R.id.lv2,R.id.lv3})
    public void onItemClick() {
        time2000();
    }

    @OnClick({R.id.ivVisaSolution, R.id.ivTransactVisa, R.id.tv_more1, R.id.tv_more2,
            R.id.tv_seoul_tourism, R.id.tv_seoul_abroad, R.id.tv_seoul_work,
            R.id.tv_seoul_more, R.id.iv1, R.id.tv_more4, R.id.ll_1, R.id.iv2,
            R.id.tv_more3})
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.ivVisaSolution:
                UIHelperIntent.gotoVisaSolutionActivity(this);
                break;
            case R.id.ivTransactVisa:
                UIHelperIntent.gotoTransactVisaActivity(this);
                break;
            case R.id.tv_more1:
            case R.id.tv_more2:
            case R.id.tv_seoul_tourism:
            case R.id.tv_seoul_abroad:
            case R.id.tv_seoul_work:
            case R.id.tv_seoul_more:
            case R.id.iv1:
            case R.id.tv_more4:
            case R.id.ll_1:
            case R.id.iv2:
            case R.id.tv_more3:
                time2000();
                break;
        }
    }

    private class MyAdapter1 extends MyBaseAdapter {
        public MyAdapter1(Context context) {
            super(context);
        }

        @Override
        protected int getLayout() {
            return R.layout.item_acticity_main1;
        }

        @Override
        protected void onInit(View convertView, int position) {
            TextView tvLine = (TextView) convertView.findViewById(R.id.tv_line);
            TextView tvPrice = (TextView) convertView.findViewById(R.id.tv_price);
            TextView tvName = (TextView) convertView.findViewById(R.id.tv_name);
            ImageView iv = (ImageView) convertView.findViewById(R.id.iv);
            if (position == 0) {
                iv.setImageResource(R.mipmap.ic_t7);
                tvName.setText("资深视觉设计师");
                tvPrice.setText("￥7k-10k");
                tvLine.setVisibility(View.VISIBLE);
            } else if (position == 1) {
                iv.setImageResource(R.mipmap.ic_t8);
                tvName.setText("平面设计师");
                tvPrice.setText("￥6k-12k");
                tvLine.setVisibility(View.VISIBLE);
            } else if (position == 2) {
                iv.setImageResource(R.mipmap.ic_t9);
                tvName.setText("产品经理");
                tvPrice.setText("￥8k-16k");
                tvLine.setVisibility(View.GONE);
            }
        }
    }

    private class MyAdapter2 extends MyBaseAdapter {
        public MyAdapter2(Context context) {
            super(context);
        }

        @Override
        protected int getLayout() {
            return R.layout.item_acticity_main2;
        }

        @Override
        protected void onInit(View convertView, int position) {
            TextView tvLine = (TextView) convertView.findViewById(R.id.tv_line);
            ImageView iv = (ImageView) convertView.findViewById(R.id.iv);
            if (position == 0) {
                iv.setImageResource(R.mipmap.ic_t4);
                tvLine.setVisibility(View.VISIBLE);
            } else if (position == 1) {
                iv.setImageResource(R.mipmap.ic_t5);
                tvLine.setVisibility(View.VISIBLE);
            } else if (position == 2) {
                iv.setImageResource(R.mipmap.ic_t6);
                tvLine.setVisibility(View.GONE);
            }
        }
    }

    private class MyAdapter3 extends MyBaseAdapter {
        public MyAdapter3(Context context) {
            super(context);
        }

        @Override
        protected int getLayout() {
            return R.layout.item_acticity_main3;
        }

        @Override
        protected void onInit(View convertView, int position) {
            TextView tvLine = (TextView) convertView.findViewById(R.id.tv_line);
            ImageView iv = (ImageView) convertView.findViewById(R.id.iv);
            if (position == 0) {
                iv.setImageResource(R.mipmap.ic_t10);
                tvLine.setVisibility(View.VISIBLE);
            } else if (position == 1) {
                iv.setImageResource(R.mipmap.ic_t11);
                tvLine.setVisibility(View.VISIBLE);
            } else if (position == 2) {
                iv.setImageResource(R.mipmap.ic_t12);
                tvLine.setVisibility(View.GONE);
            }
        }
    }
}
